Week 2 Computer Science Notes: Arrays & Forensic Debugging
Section 1: The Etymology of "Bug" & Forensic Code Diagnostics
The architectural convention of designating software aberrations as Bugs traces directly to Rear Admiral Dr. Grace Hopper and her engineering contingent operating the Harvard Mark II mainframe computer. Upon investigating a physical circuitry malfunction, the team discovered an actual moth trapped between the physical relay contacts. The historical notation inscribed into the operational logbook remains iconic: "First actual case of bug being found."
===================================================================================
HISTORICAL ARCHITECTURE: THE FIRST BUG (HARVARD MARK II)
===================================================================================
[ Relay Circuitry ] ββ> [ Physical Moth Intercepted ] ββ> [ System Short Circuit ]
β
βΌ
[ Recorded in Logbook: "First actual bug" ]
β
βΌ
[ Birth of Modern Debugging Paradigm ]
===================================================================================
- Syntax Errors: Fatal structural anomalies that abort compilation immediately (e.g., missing semicolons
;or unreferenced<stdio.h>headers). The compiler possesses no intuitive cognition to infer logical intent. - Logical Errors: The codebase compiles flawlessly but manifests unintended runtime behavior (e.g., executing a
forloop four times instead of three). - Forensic Debugging via printf: The primary manual diagnostic technique for software engineers in the absence of automated assistance involves strategically injecting
printfinspection statements into loop control logic to monitor live stack memory indices.
Section 2: Function Prototypes & Training Wheels
The C compiler parses translation units sequentially from top to bottom. If the main entry point invokes a custom subroutine such as print_column prior to its explicit declaration, compilation is instantly halted due to an implicit declaration error.
===================================================================================
FUNCTION PROTOTYPE PIPELINE
===================================================================================
[ Line 1: void print_column(int height); ] ββ> Prototype informs compiler
[ Line 3: int main(void) { print_column(3); } ] ββ> Safe execution in main
[ Line 10: void print_column(int height) { ... } ] ββ> Actual dynamic implementation
===================================================================================
- Architectural Remedy (Function Prototype): Duplicating the function signature above
mainappended with a terminal semicolon;. - The Truth Behind the CS50 Library ("Training Wheels"): In bare-metal C, there is no inherent
stringdata type. TheCS50.hwrapper functions as temporary bicycle training wheels (Training Wheels), designed to encapsulate and obscure the complex physics of pointers during introductory modules, preparing students for the eventual unmasking of raw character pointerschar *.
Section 3: Cryptographic Protocols & Text Parsing
David Malan explores the systemic evaluation of divergent reading texts (spanning rudimentary kindergarten prose like One Fish, Two Fish to complex excerpts from George Orwell's 1984). Algorithmic logic enables the construction of mathematical indices that scan in-memory string arrays to calculate letter, word, and sentence ratios, definitively determining academic readability.
- Encryption: The mechanical transformation of cleartext (Plaintext) into obfuscated information (Ciphertext) using a highly secure mathematical key.
- Decryption: Reversing the mathematical transformation to restore cleartext integrity.
- Forensic Imperative: Assuring absolute end-to-end communication security even if a malicious actor successfully intercepts physical communication channels.